rm(list=ls())

source("binary.R")
source("cluster.R")

ComputeAndPrintResults <- function(simulation, designs, nsim, nsimb) {
    tables <- list()

    print(sprintf("nsim: %g, nsimb: %g", nsim, nsimb))

    for (t in names(designs)) {
        cat("\n\n\nDESIGN:", t, "\n\n")       # circle 8.1.22 of R inferno
        print(c(designs[[t]], time=as.character(Sys.time())))
        tables[[t]] <- simulation(nsim, nsimb, dc=designs[[t]])
        print(tables[[t]])
    }
    tables
}

sink(file=paste("results", Sys.time(),".txt", sep=""))

## Simulation designs for Tables 1--3
ptm <- proc.time()                      # start the clock

APDesigns <- list(Table1=list(n0=27, n1=3, distr0="Normal", distr1="Normal"),
                  Table2=list(n0=27, n1=3, distr0="logNormal",
                              distr1="logNormal"),
                  Table3=list(n0=15, n1=15, distr0="Normal", distr1="Normal"))
APTables <- ComputeAndPrintResults(APSimulation, APDesigns,
                                   nsim=1000000, nsimb=100000)

## Simulation designs for Tables 4--5
ClDesigns <- list(Table4=as.character(seq(5)), Table5=as.character(c(6:9,11)))
ClTables <- ComputeAndPrintResults(ClSimulation, ClDesigns,
                                   nsim=100000, nsimb=10000)

print(proc.time()-ptm)

sink()
